<?php

namespace App\Service\Moment;

use App\Constants\ErrorCode;
use App\Model\Moment;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 动态详情
 */
class MomentDetailService extends BaseService
{
    public function handle()
    {
        $this->isNewVersion = $this->request->input('version', '1.0') >= '1.1.2';
        //动态详情
        $momentId = $this->request->input('moment_id', 0);
        if (!$momentId) return $this->setError(ErrorCode::PARAMETER_ERROR);
        $moment = Moment::getItem($momentId);
        if (!$moment) return $this->setError(ErrorCode::PARAMETER_ERROR, '该动态不存在！');
        $profile = UserProfile::getProfile($moment->user_id);
        $ret = Moment::buildItem($moment, $profile, $this->getUserId());
        if (!$this->isNewVersion && $ret['video']) {
            $ret['words'] = '该动态为视频动态，请升级版本后查看~';
        }
        $ret['show_comment'] = 0;
        return $ret;
    }
}
